<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>大麦</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        .menu {
            display: flex;
        }
        
        .menu li {
            padding: 5px 20px;
            margin: 0 10px;
            cursor: pointer;
            border-radius: 5px;
        }
        
        .menu li.active {
            background-color: orangered;
            color: #fff;
        }
        
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak style="width: 100%; height: 100%;">
        <!-- <input type="text" v-model='fname'>
        <input type="text" v-model='lname'> -->
        <!-- 模板内尽量避免这样写  用计算属性-->
        <!-- <h1>{{fname+lname}}</h1> -->
        <!-- 计算 -->
        <!-- <h1>{{realname}}</h1> -->


        <div style="width: 1000px;border: 1px solid red;margin: 100px auto;">
            <div class="menu">
                <li>城市:</li>
                <li @click="activeCityIndex = i" :class="{active:i===activeCityIndex}" v-for="(item,i) in citylist">{{item.name}}</li>
            </div>
            <div class="menu">
                <li>类型:</li>
                <li @click="activeTypeIndex = i" :class="{active:i===activeTypeIndex}" v-for="(item,i) in typelist">{{item.name}}</li>
            </div>

            <!-- <h1>共{{this.showlist.length}}条演出信息</h1> -->
            <h1>共{{showcount}}条演出信息</h1>
            <ul>
                <li style="display: flex;padding: 20px 20px;margin: 0 auto;width: 1000px;" v-for="(item,i) in showlist">
                    <a :href="'detail.html?id='+item.id" target="_blank">
                        <img :src="item.verticalPic" style="width: 150px; height: 200px;">
                    </a>

                    <div>
                        <div>{{item.name}}</div>
                        <div>{{item.actors}}</div>
                        <div>{{item.categoryname}}</div>
                    </div>

                </li>
            </ul>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        // {
        //     active: i === activeCityIndex
        // }   一个对象中 active为一个属性     后面是true或false  代表有 或没有这个active属性 :class可放入对象

        // Vue.config.devtools = false
        Vue.config.productionTip = false

        Vue.component('mytype', {
            template: `
                
            `
        })


        let vm = new Vue({
            created() {
                //数据准备好了  ajax
                this.getShowList()
            },
            mounted() {
                //DOM 准备好了  Echarts  layui

            },
            el: "#app",
            computed: {
                realname() {
                    return this.fname + ' ' + this.lname
                },
                showcount() {
                    return this.showlist.length
                }
            },

            //侦听器 侦听变量变化
            watch: {
                activeCityIndex(val) {
                    this.getShowList()
                },
                activeTypeIndex(val) {
                    this.getShowList()
                }
            },
            data() {
                return {
                    fname: "",
                    lname: "",
                    showlist: [],
                    activeCityIndex: 0,
                    citylist: [{
                        id: 0,
                        name: "全部"
                    }, {
                        id: 1,
                        name: "南京"
                    }, {
                        id: 2,
                        name: "上海"
                    }, {
                        id: 3,
                        name: "重庆"
                    }, {
                        id: 4,
                        name: "苏州"
                    }],

                    activeTypeIndex: 0,
                    typelist: [{
                        id: 0,
                        name: "全部"
                    }, {
                        id: 1,
                        name: "演唱会"
                    }, {
                        id: 2,
                        name: "戏剧"
                    }, {
                        id: 3,
                        name: "体育比赛"
                    }]
                }
            },
            methods: {
                async getShowList() {
                    let cityid = this.citylist[this.activeCityIndex].id
                    let typeid = this.typelist[this.activeTypeIndex].id
                    console.log(cityid, typeid, '1')
                    let res = await axios.get('show.json')
                    let arr = res.data

                    //不为0 代表不是选全部
                    if (cityid) {
                        arr = arr.filter(r => r.cityid === cityid)
                    }

                    if (typeid) {
                        arr = arr.filter(r => r.categoryid === typeid)
                    }
                    this.showlist = arr
                }
            },
        })
    </script>
</body>

</html>